<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>equationeditorplugin_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_equationeditorplugin_test.js.html">equationeditorplugin_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.EquationEditorPluginTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.EquationEditorPluginTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.DomHelper&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line21"></a>goog.require(&#39;goog.editor.plugins.EquationEditorPlugin&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.MockControl&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.MockRange&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.mockmatchers.ArgumentMatcher&#39;);
<a name="line28"></a>goog.require(&#39;goog.ui.editor.EquationEditorOkEvent&#39;);
<a name="line29"></a>
<a name="line30"></a>var plugin;
<a name="line31"></a>var imgElem;
<a name="line32"></a>
<a name="line33"></a>var mockCtrl;
<a name="line34"></a>var mockRange;
<a name="line35"></a>var mockField;
<a name="line36"></a>var mockEditor;
<a name="line37"></a>var mockPlaceCursorNextTo;
<a name="line38"></a>var propertyReplacer = new goog.testing.PropertyReplacer();
<a name="line39"></a>var fieldObj;
<a name="line40"></a>var fieldElem;
<a name="line41"></a>var domHelper = new goog.dom.DomHelper();
<a name="line42"></a>var IMG_URL = &#39;https://www.google.com/chart?cht=tx&amp;chf=bg,s,&#39; +
<a name="line43"></a>              &#39;FFFFFF00&amp;chco=000000&amp;chl=x^2%2Fy^2&#39;;
<a name="line44"></a>
<a name="line45"></a>function setUp() {
<a name="line46"></a>  mockCtrl = new goog.testing.MockControl();
<a name="line47"></a>  mockRange = new goog.testing.MockRange();
<a name="line48"></a>  mockCtrl.addMock(mockRange);
<a name="line49"></a>  mockField = new goog.testing.editor.FieldMock(undefined, undefined,
<a name="line50"></a>                                                mockRange);
<a name="line51"></a>  mockCtrl.addMock(mockField);
<a name="line52"></a>  mockPlaceCursorNextTo = mockCtrl.createFunctionMock(&#39;placeCursorNextTo&#39;);
<a name="line53"></a>}
<a name="line54"></a>
<a name="line55"></a>function tearDown() {
<a name="line56"></a>  plugin.dispose();
<a name="line57"></a>}
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Sets up expectations for testing when the OK event fires: the field is
<a name="line62"></a> * focused, the image is inserted.
<a name="line63"></a> * @param {string} imageUrl Url of the image being inserted.
<a name="line64"></a> */
<a name="line65"></a>function setUpTestOk(imageUrl) {
<a name="line66"></a>  mockField.focus().$times(1);
<a name="line67"></a>  var tempImage = goog.dom.createDom(goog.dom.TagName.IMG, {src: imageUrl});
<a name="line68"></a>  var fullImageUrl = tempImage.src;
<a name="line69"></a>  var createdNodeMatcher = new goog.testing.mockmatchers.ArgumentMatcher(
<a name="line70"></a>      function(arg) {
<a name="line71"></a>        if (!arg) {
<a name="line72"></a>          return true;
<a name="line73"></a>        }
<a name="line74"></a>        return arg.tagName == goog.dom.TagName.IMG &amp;&amp;
<a name="line75"></a>            arg.src == fullImageUrl;
<a name="line76"></a>      },
<a name="line77"></a>      &#39;&lt;IMG src=&quot;&#39; + imageUrl + &#39;&quot;&gt;&#39;);
<a name="line78"></a>  mockPlaceCursorNextTo(createdNodeMatcher, false);
<a name="line79"></a>  mockRange.isCollapsed().$times(1);
<a name="line80"></a>  mockRange.removeContents().$times(1);
<a name="line81"></a>  mockRange.insertNode(
<a name="line82"></a>      domHelper.htmlToDocumentFragment(imageUrl), false).$times(1);
<a name="line83"></a>  propertyReplacer.setPath(
<a name="line84"></a>      &#39;goog.editor.range.placeCursorNextTo&#39;, mockPlaceCursorNextTo);
<a name="line85"></a>  mockField.dispatchChange().$times(1);
<a name="line86"></a>}
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>/**
<a name="line90"></a> * Tests that when the OK event fires the editable field is properly updated.
<a name="line91"></a> */
<a name="line92"></a>function testOk() {
<a name="line93"></a>  setUpTestOk(IMG_URL);
<a name="line94"></a>  mockField.dispatchBeforeChange().$times(1);
<a name="line95"></a>  mockCtrl.$replayAll();
<a name="line96"></a>
<a name="line97"></a>  plugin = new goog.editor.plugins.EquationEditorPlugin();
<a name="line98"></a>  plugin.registerFieldObject(mockField);
<a name="line99"></a>  var dialog = plugin.createDialog(domHelper);
<a name="line100"></a>  // Mock of execCommand + clicking OK without actually opening the dialog.
<a name="line101"></a>  dialog.dispatchEvent(
<a name="line102"></a>      new goog.ui.editor.EquationEditorOkEvent(IMG_URL));
<a name="line103"></a>  mockCtrl.$verifyAll();
<a name="line104"></a>}
</pre>


</body>
</html>
